package com.lanou.controller;

import com.github.pagehelper.PageInfo;
import com.lanou.bean.Role;
import com.lanou.service.ModuleService;
import com.lanou.service.RoleService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by dllo on 18/3/12.
 */
@Controller
public class RoleController {
    @Resource
    private RoleService roleService;

    @RequestMapping(value = "/rolelist")
    public String rolelist() {
        return "/role/role_list";
    }

    @ResponseBody
    @RequestMapping(value = "/rolePage")
    public PageInfo<Role> roles(@RequestParam("pagenum") Integer pageNo) {
        return roleService.queryRoleByPage(pageNo, 3);
    }

    @RequestMapping(value = "/roleadd")
    public String add() {
        return "/role/role_add";
    }

    @ResponseBody
    @RequestMapping(value = "/addRole")
    public void addRole(@RequestParam("rolename") String rolename, @RequestParam("modules[]") List<Integer> modules) {
        roleService.addrole(rolename, modules);
    }

    @RequestMapping(value = "/roleupdate")
    public String update() {
        return "role/role_modi";
    }

    @ResponseBody
    @RequestMapping(value = "/modiRole")
    public void modiRole(@RequestParam("roleId") Integer roleId, @RequestParam("rolename") String rolename, @RequestParam("modules[]") List<Integer> modules) {
        roleService.updata(roleId, rolename, modules);
    }

    @ResponseBody
    @RequestMapping(value = "/deleteRole")
    public void delete(@RequestParam("roleId") Integer roleId) {
        roleService.delete(roleId);
    }

    @ResponseBody
    @RequestMapping(value = "/allRole")
    public List<Role> allRole() {
        return roleService.allRole();
    }

}
